package com.lanou.tk.tourism.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.lanou.tk.tourism.R;
import com.lanou.tk.tourism.entity.Hot_country;
import com.lanou.tk.tourism.tool.GetBitmaps;

import java.util.List;


/**
 * Created by dllo on 15/10/28.
 */
public class CommunityRvAdapter extends RecyclerView.Adapter<CommunityRvAdapter.LatestViewHolder>{

    List<Hot_country> hot_countries;
    private RequestQueue queue;
    private LruCache<String, Bitmap> lruCache;


    public CommunityRvAdapter(Context c){
        queue = Volley.newRequestQueue(c);
    }

    public void addDatas(List<Hot_country> datas){
        hot_countries = datas;
        notifyDataSetChanged();
    }




    @Override
    public LatestViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View v = inflater.inflate(R.layout.community_rv_adp,null);


        return new LatestViewHolder(v);
    }

    @Override
    public void onBindViewHolder(LatestViewHolder holder, int position) {

        if(hot_countries != null && hot_countries.size() > 0){
            Hot_country hot_country = hot_countries.get(position);
            holder.community_count.setText(hot_country.getCount());
            holder.community_cnname.setText(hot_country.getCnname());
            holder.community_enname.setText(hot_country.getEnname());


            String imgUrl = hot_country.getPhoto();
            GetBitmaps.getBitmapRequest(imgUrl, holder.community_photo);


        }
    }




    @Override
    public int getItemCount() {
        return hot_countries != null && hot_countries.size() > 0 ? hot_countries.size() : 0;
    }

    public class LatestViewHolder extends RecyclerView.ViewHolder {
        private ImageView community_photo;
        private TextView community_count,community_cnname,community_enname;


        public LatestViewHolder(View itemView) {
            super(itemView);

            community_count = (TextView) itemView.findViewById(R.id.community_count);
            community_cnname = (TextView) itemView.findViewById(R.id.community_cnname);
            community_enname = (TextView) itemView.findViewById(R.id.community_enname);
            community_photo = (ImageView) itemView.findViewById(R.id.community_photo);




        }
    }




}
